package com.example.teach.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.teach.entity.Article;
import com.example.teach.entity.Result;
import com.example.teach.entity.User;
import com.example.teach.service.ArticleService;
import com.example.teach.service.UserService;
import com.example.teach.vo.ArticleVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @Autowired
    private UserService userService;

    @PostMapping("/add")
    public Result add(@RequestBody ArticleVO articleVO) {
        return articleService.add(articleVO);
    }

    @GetMapping("/page")
    public Result page(@RequestParam(value="pageNum",defaultValue="1") Integer pageNum,
                       @RequestParam(value="pageSize",defaultValue="10") Integer pageSize,
                       @RequestParam(required = false) String str){
        return articleService.articlePage(pageNum,pageSize,str);
    }

    @GetMapping("/category")
    public Result category(@RequestParam(value="pageNum",defaultValue="1") Integer pageNum,
                           @RequestParam(value="pageSize",defaultValue="10") Integer pageSize,
                           @RequestParam Integer categoryId){
        return articleService.pageByCategery(pageNum,pageSize,categoryId);

    }

    @PostMapping("/view")
    public void view(@RequestParam Integer id){
        articleService.addOne(id);
    }

    @PostMapping("/like")
    public Result like(@RequestParam Integer userId,@RequestParam Integer articleId){
        return articleService.like(userId,articleId);
    }

}
